package team.seekers.skill.security.handler;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import team.seekers.skill.common.utils.ResponseUtil;
import team.seekers.skill.result.Result;
import team.seekers.skill.security.TokenManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Godc
 * @description
 */
public class TokenOutHandler implements LogoutHandler {
//    private TokenManager tokenManager;
    private RedisTemplate redisTemplate;
    //构造两个参数
    public TokenOutHandler(RedisTemplate redisTemplate) {
//        this.tokenManager = tokenManager;
        this.redisTemplate = redisTemplate;
    }

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        //从redis中移除掉登录信息
        String token = request.getHeader("token");
        redisTemplate.delete("token");
        ResponseUtil.out(response, Result.success());
    }
}
